package com.lul15834.orderfood.activity.manager.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lul15834.orderfood.R;
import com.lul15834.orderfood.activity.manager.ManagerUpdateFood;
import com.lul15834.orderfood.bean.CommentBean;
import com.lul15834.orderfood.bean.UserComBean;
import com.lul15834.orderfood.dao.AdminDao;
import com.lul15834.orderfood.dao.FoodDao;

import java.util.List;

/**
 * 显示商家商品的adapter
 */
public class CommentListAdapter extends ArrayAdapter<CommentBean> {
    private List<CommentBean> list;
    private Context context;
    public CommentListAdapter(@NonNull Context context, List<CommentBean> list){
        super(context, R.layout.list_man_food_list,list);
        this.context=context;
        this.list=list;
    }
    @Override
    public View getView(int position,View convertView, ViewGroup viewGroup){
        // position数据的位置，convertView可重用的视图对象，viewGroup父容器，测量和布局子视图
        if (convertView==null){
            LayoutInflater inflater=LayoutInflater.from(getContext());
            convertView=inflater.inflate(R.layout.list_comment,viewGroup,false);
        }
        CommentBean tem=list.get(position);
        String userId=tem.getSCommentUserId();
        UserComBean common= AdminDao.getComUser(userId);
        ImageView img=convertView.findViewById(R.id.comment_img);
        img.setImageBitmap(BitmapFactory.decodeFile(common.getsImg()));
        TextView name=convertView.findViewById(R.id.comment_name);
        name.setText(common.getsName());
        TextView time=convertView.findViewById(R.id.comment_time);
        time.setText(tem.getSCommentTime());
        TextView c=convertView.findViewById(R.id.comment_con);
        convertView.setOnClickListener(null);
        //显示评分内容
        int scoreZ=Integer.valueOf(tem.getSCommentScore()) ;
        String conZ[]={"非常差","差","一般","满意","非常满意"};//代表五个内容
        int icoIdZ[]={R.id.comment_one,R.id.comment_two,R.id.comment_three,R.id.comment_four,R.id.comment_five};
        c.setText(conZ[scoreZ-1]);
        for (int i=scoreZ;i<5;i++){
            ImageView temp=convertView.findViewById(icoIdZ[i]);
            temp.setImageResource(R.drawable.wxx);
        }
        for (int i=0;i<scoreZ;i++){
            ImageView temp=convertView.findViewById(icoIdZ[i]);
            temp.setImageResource(R.drawable.xx);
        }
        TextView userCon=convertView.findViewById(R.id.comment_user_con);
        userCon.setText(tem.getSCommentContent());
        ImageView imgZ=convertView.findViewById(R.id.comment_user_img);
        if (tem.getSCommentImg().equals("")){
            imgZ.setVisibility(View.GONE);
        }else {
            imgZ.setImageBitmap(BitmapFactory.decodeFile(tem.getSCommentImg()));
        }
        return convertView;
    }
}

